<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tansible 执行结果</title>
    <script src="https://unpkg.com/@tailwindcss/browser@4"></script>
    <style>
        body {
            font-family: 'Inter', sans-serif;
            background-color: #f4f4f9;
            color: #333;
            line-height: 1.5;
            letter-spacing: 0.02em;
        }

        .container {
            max-width: 2500px;
            margin: 0 auto;
            padding: 2rem;
        }

        h1 {
            font-size: 2.25rem;
            font-weight: 700;
            text-align: center;
            color: #2d3748;
            margin-bottom: 2rem;
        }

        table {
            border-collapse: collapse;
            width: 100%;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            background-color: #fff;
        }

        th,
        td {
            border: 1px solid #e2e8f0;
            padding: 1rem;
            text-align: left;
        }

        th {
            background-color: #edf2f7;
            font-weight: 600;
            text-transform: uppercase;
            font-size: 0.875rem;
        }

        tr:nth-child(even) {
            background-color: #f7fafc;
        }

        tr:hover {
            background-color: #edf2f7;
            transition: background-color 0.3s ease;
        }

       .failed-row {
            color: red;
        }

       .error {
            color: red;
            text-align: center;
            font-size: 1.25rem;
        }

       .input-info {
            margin-bottom: 2rem;
            padding: 1rem;
            background-color: #edf2f7;
            border-radius: 0.375rem;
        }

       .back-button {
            display: block;
            margin-top: 2rem;
            background-color: #4299e1;
            color: #fff;
            padding: 0.75rem 1.5rem;
            border: none;
            border-radius: 0.375rem;
            text-align: center;
            text-decoration: none;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

       .back-button:hover {
            background-color: #3182ce;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>Tansible 执行结果</h1>
        <div class="input-info">
            <h2 class="text-xl font-bold mb-2">执行参数</h2>
            <p><strong>主机文件路径:</strong> {{ host_file_path }}</p>
            <p><strong>群组文件路径:</strong> {{ group_file_path }}</p>
            <p><strong>动作文件路径:</strong> {{ action_file_path }}</p>
            <p><strong>并发线程数:</strong> {{ max_workers }}</p>
        </div>
        {% if error %}
        <p class="error">{{ error }}</p>
        {% else %}
        <table>
            <thead>
                <tr>
                    <th style="width: 5%">执行结果</th>
                    <th style="width: 15%">任务</th>
                    <th style="width: 10%">模块名</th>
                    <th style="width: 15%">主机名</th>
                    <th style="width: 5%">执行秒数</th>
                    <th style="width: 50%">返回结果</th>
                </tr>
            </thead>
            <tbody>
                {% for item in result %}
                <tr class="{% if item.status == 'failed' %}failed-row{% endif %}">
                    <td style="white-space: nowrap">{{ item.status }}</td>
                    <td style="white-space: nowrap">{{ item.taskname }}</td>
                    <td style="white-space: nowrap">{{ item.modelname }}</td>
                    <td style="white-space: nowrap">{{ item.hostname }}</td>
                    <td style="white-space: nowrap">{{ item.costtime|round(0) }}</td>
                    <td style="white-space: normal">{{ item.msg.replace('\n', '<br>')|safe }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% endif %}
        <a href="/" class="back-button">返回首页</a>
    </div>
</body>

</html>